/**
 * @api {get} /api/admin/v1/refunds/analyse 维权订单统计
 * @apiGroup AdminOrders
 * @apiDescription 维权订单管理-维权订单统计
 * @apiPermission 管理员(查看维权订单权限)
 * @apiVersion 1.0.0
 */
exports.analyse = function ({}, {models: {TaokeRefunds}}) {
    return TaokeRefunds.analyseV2();
}

/**
 * @api {get} /api/admin/v1/refunds/browse 维权订单列表
 * @apiGroup AdminOrders
 * @apiDescription 维权订单管理-维权订单列表
 * @apiPermission 管理员(查看维权订单权限)
 * @apiVersion 1.0.0
 */
exports.browse = function ({query}, {models: {TaokeRefunds, Users, associations}, controller}) {
    let pagination = controller.pagination({
        params: query,
        filters: ['id', 'partner_id', 'agency_id', 'user_id', 'tbAuctionId', 'payStatus', 'is_back', 'showRefundStatus', 'status', 'tbTradeParentId'],
        likes: ['tbTradeParentId', 'user_id', 'agency_id']
    });
    return TaokeRefunds.findAndCountAll(pagination).then(function (data) {
        return associations.relateOne(data, Users, 'user_id', 'user', ['id', 'image', 'username', 'nickname', 'tel', 'order_count', 'finish_count', 'sham_count', 'amount', 'frozen']);
    }).then(function (data) {
        return associations.relateOne(data, Users, 'partner_id', 'partner', ['id', 'image', 'username', 'nickname', 'tel']);
    }).then(function (data) {
        return associations.relateOne(data, Users, 'agency_id', 'agency', ['id', 'image', 'username', 'nickname', 'tel']);
    });
}
